package Class::Scaffold::Log_TEST;

# $Id: Log_TEST.pm 12992 2007-03-20 14:52:19Z gr $

use strict;
use warnings;
use Test::More;


our $VERSION = '0.03';


use base 'Class::Scaffold::Test';


use constant PLAN => 2;


sub run {
    my $self = shift;
    $self->SUPER::run(@_);

    # Use different ways of accessing the log: via the singleton object, or by
    # using the feature of turning a class method call into an instance call.

    my $log = $self->make_real_object->instance;
    isa_ok($log, $self->package);

    # manually turn off test mode so that the log won't output to STDERR; after
    # all, that's exactly what we want to test.

    $log->delegate->test_mode(0);

    $log->info('Hello');
    Class::Scaffold::Log->debug('a debug message that should not appear');
    $log->max_level(2);
    Class::Scaffold::Log->debug('a debug message that should appear');
    $log->set_pid;
    Class::Scaffold::Log->info('a message with %s and %s', qw/pid timestamp/);
    $log->clear_timestamp;
    $log->info('a message with pid but without timestamp');
    Class::Scaffold::Log->instance->clear_pid;
    Class::Scaffold::Log->instance->info('a message without pid or timestamp');

    (my $out = $log->output) =~ s/^\d{8}\.\d{6}\.\d\d/[timestamp]/mg;
    my $pid = sprintf '%08d', $$;

    is($out, <<EXPECT, 'log output');
[timestamp] Hello
[timestamp] a debug message that should appear
[timestamp] ($pid) a message with pid and timestamp
($pid) a message with pid but without timestamp
a message without pid or timestamp
EXPECT

}


1;


__END__

{% USE p = PodGenerated %}

=head1 NAME

{% p.package %} - large-scale OOP application support

=head1 SYNOPSIS

    {% p.package %}->new;

=head1 DESCRIPTION

=head1 METHODS

=over 4

{% p.write_methods %}

=back

{% p.write_inheritance %}

{% PROCESS standard_pod %}

=cut

